﻿using System.Linq;
using System.Web.Services;
using CounterServerModel;
using CounterServerModel.Authentication;

namespace SmartCounters.WebServices
{
    /// <summary>
    /// This is a Web Service that represents the Information Reader in the model of the system.
    /// </summary>
    [WebService(Namespace = "http://smartcounters.org")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class InformationReaderWebService : WebService
    {
        [WebMethod]
        public UserInfo GetUserInformationByID(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, int i_UserID)
        {
            return new InformationReader().GetUserInformation(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_UserID);
        }

        [WebMethod]
        public UserInfo GetUserInformationByUsername(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, string i_Username)
        {
            return new InformationReader().GetUserInformation(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_Username);
        }

        [WebMethod]
        public AccountInfo GetAccountInformation(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, int i_AccountID)
        {
            return new InformationReader().GetAccountInformation(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_AccountID);
        }

        [WebMethod]
        public AccountInfo[] GetAllAccounts(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword)
        {
            return new InformationReader().GetAllAccounts(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword)).ToArray();
        }

        [WebMethod]
        public UserInfo[] GetAllUsers(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword)
        {
            return new InformationReader().GetAllUsers(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword)).ToArray();
        }

        [WebMethod]
        public bool IsUserExists(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, string i_Username)
        {
            return new InformationReader().IsUserExists(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_Username);
        }

        [WebMethod]
        public bool IsAccountExistsWithoutApartment(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, string i_Country, string i_City, string i_Street, int i_House)
        {
            return new InformationReader().IsAccountExists(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_Country, i_City, i_Street, i_House, null);
        }

        [WebMethod]
        public bool IsAccountExistsWithApartment(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, string i_Country, string i_City, string i_Street, int i_House, int i_Apartment)
        {
            return new InformationReader().IsAccountExists(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_Country, i_City, i_Street, i_House, i_Apartment);
        }

        [WebMethod]
        public Fault GetFaultInformation(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, int i_FaultID)
        {
            return new InformationReader().GetFaultInformation(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_FaultID);
        }

        [WebMethod]
        public Fault[] GetAllOpenFaults(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword)
        {
            return new InformationReader().GetAllOpenFaults(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword)).ToArray();
        }

        [WebMethod]
        public Fault[] GetAllOpenFaultsForAccount(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, int i_AccountID)
        {
            return new InformationReader().GetAllOpenFaults(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_AccountID).ToArray();
        }
    }
}
